package com.tieba.mapper;


import com.tieba.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {


    /**
     * 查询用户
     *
     * @return
     */
    @Select("select * from user")
    List<User> list();

    /**
     * 根据用户id查询用户
     */
    @Select("select * from user where id=#{id}")
    User getById(int id);

    /**
     * 新增用户
     * @param user
     */
    @Insert("insert into user (username, password, permission, gender, image, phone, email, address,introduction, create_time, update_time) " +
            "values (#{username},#{password},#{permission},#{gender},#{image},#{phone},#{email},#{address},#{introduction},#{createTime},#{updateTime})")
    void insert(User user);

    /**
     * 删除用户，xml注解实现
     * @param ids
     */
    void delete(List<Integer> ids);

    /**
     * 修改/更新用户数据,xml注解实现
     * @param user
     */
    void update(User user);

    /**
     * 根据用户名和密码查询用户
     * @param user
     * @return
     */
    @Select("select * from user where username = #{username} and password = #{password}")
    User getByUsernameAndPassword(User user);

    /**
     * 根据用户名查询，用于注册新用户时查重
     * @param user
     * @return
     */
    @Select("select * from user where username = #{username}")
    User getByUsername(User user);


}
